#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    vector<long long> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    sort(v.begin(),v.end());
    //一堆数变成一样，差最小就是变成中间，偶数的话任选一个
    vector<long long> dp(n);//前缀和
    dp[0]=v[0];
    for(int i=1;i<n;i++)
    {
        dp[i]=dp[i-1]+v[i];
    }
    //序列变长后的花费肯定是>=变长前的
    int left=0;
    int ret=1;
    for(int right=0;right<n;right++)
    {
        int mid=(left+right)/2;
         long long cost;
        if(left==0)
        {
            cost = (mid-left+1)*v[mid]-dp[mid]+dp[right]-dp[mid]-(right-mid)*v[mid];
        }
        else
        {
             cost = (mid-left+1)*v[mid]-(dp[mid]-dp[left-1])+dp[right]-dp[mid]-(right-mid)*v[mid];
        }
       
        while(cost>k)//left++后包不会越界的
        {
            left++;
            mid=(left+right)/2;
            cost=(mid-left)*v[mid]-(dp[mid-1]-dp[left-1])+dp[right]-dp[mid]-v[mid]*(right-mid);

        }
        ret=max(ret,right-left+1);
       
    }
    cout<<ret;
    
    
    return 0;
}